package beusoft.ccjk.com.calculator;

import com.sun.corba.se.pept.transport.InboundConnectionCache;

import java.util.Collection;
import java.util.Random;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by CCJK on 2018/12/8.
 */

public class Solution {
    public static class TreeNode {
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;

        public TreeNode(int val) {
            this.val = val;

        }

    }

    public static void main(String... args) {

 int len=3;
        int[] nums = new int[len];
//        Random random = new Random();
//        for (int i = 0; i < len; i++) {
//            nums[i] = random.nextInt(500);
//        }
        nums[0]=3334;
        nums[1]=3;
        nums[2]=3333332;
        Solution solution = new Solution();
//        solution.sort(nums);
        System.out.println(solution.gt(3334, 3));
//        for (int i=0;i<len;i++){
//            System.out.println(nums[i]);
//        }


    }

    public void sort(int[] arr) {
        int len = arr.length;
        for (int i = 1; i < len; i++) {
            int index = i;
            int temp = arr[i];
            for (int j = i - 1; j >= 0; j--) {
                if (gt(arr[j], temp)) {
//                if ((temp<arr[j])) {
                    arr[j + 1] = arr[j];
                    index = j;
                } else {
                    break;
                }
            }
            if (index != i) {
                arr[index] = temp;
            }
        }

    }


    /**
     * @param a
     * @param b
     * @return a>b true else false
     */
    public boolean gt(int a, int b) {
        if (a == b) return false;
        String aString = a + "";
        String bString = b + "";
        int lenA = aString.length();
        int lenB = bString.length();
        int minLen = lenA > lenB ? lenB : lenA;

        for (int i = 0; i < minLen; i++) {
            char cA = aString.charAt(i);
            char cB = bString.charAt(i);
            if (cA > cB) {
                return true;
            } else if (cA < cB) {
                return false;
            }
        }
        if (minLen == lenA && minLen == lenB) {
            return false;
        }
        if (minLen == lenA) {

            for (int k=minLen;k<lenB;k++){
                char lenChar = bString.charAt(k);
                for (int i = 0; i < minLen; i++) {
                    char cP = bString.charAt(i);
                    if (cP < lenChar) {
                        return false;
                    } else if (cP > lenChar) {
                        return true;
                    }
                }
            }
            return false;
        } else {
            for (int k=minLen;k<lenA;k++){
                char lenChar = aString.charAt(k);
                for (int i = 0; i < minLen; i++) {
                    char cP = aString.charAt(i);
                    if (cP < lenChar) {
                        return true;
                    } else if (cP > lenChar) {
                        return false;
                    }
                }
            }

            return false;
        }
    }

}
